@model viBook.Models.Chapter
@{
    ViewBag.Title = "Create Chapter";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section HeadContent{              
    <link href="../../Scripts/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/uploadify/swfobject.js" type="text/javascript"> </script>
    <script src="../../Scripts/uploadify/jquery.uploadify.v2.1.4.min.js" type="text/javascript"> </script>
}
<div class="group">
    <div class="full">
        <h1>Chapters</h1>
    </div>
</div>
@using (Html.BeginForm("Create", "Chapters", FormMethod.Post, new { id = "CreatChapterForm", @class = "gen-form" }))
{
    <div id="main">
        <ul class="tabs">
            <li class="active">@Html.ActionLink("Create chapter", "Create", "Chapters")</li>            
        </ul>
        @Html.ValidationSummary(true)
        <fieldset>
            @Html.Partial("_CreateOrEdit", Model)
        
            <div class="form-field" id="upload_chapter">
                <input type="hidden" id="fileUploadInfo" name="fileUploadInfo" />
                <br />
                <input id="file_upload" name="file_upload" type="file" />
            </div>
            <div class="form-btns">
                <input type="button" class="form-sub" onclick="$('#file_upload').uploadifyUpload();" value="Create" />
                <a class="form-btn" href="@Request.UrlReferrer">Cancel</a>
            </div>
        </fieldset>
    </div>
}
<script type="text/javascript">
    // Multiple files - single input

    var bookid = @Model.BookId ;

    $("#file_upload").uploadify({
        'uploader': '/Scripts/uploadify/uploadify.swf',
        'script': '@Url.Action("UploadFiles")',
        'buttonText': 'Select files',
        'multi': true,
        'scriptData': { 'path':bookid},
        'sizeLimit': 20000000,
        'cancelImg': '/Scripts/uploadify/cancel.png',
        'auto': false,
        'removeCompleted': true,
        'simUploadLimit': 1,
        'fileExt'     : '*.jpg;*.gif;*.png',
        'fileDesc'    : 'Image Files',
        'onError': function(a, b, c, d) {
            if (d.status == 404)
                alert("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>");
            else if (d.type === "HTTP")
                alert("error " + d.type + ": " + d.status);
            else if (d.type === "File Size")
                alert(c.name + " " + d.type + " Limit: " + Math.round(d.info / (1024 * 1024)) + "MB");
            else
                alert("error " + d.type + ": " + d.text);

        },
        'onComplete': function(event, id, fileObj, response, data) {
            $("#fileUploadInfo").val($("#fileUploadInfo").val() + ";" + response);
        },

        'onAllComplete': function(event, queueId, fileObj, response, data) {
            $("#CreatChapterForm").submit();

        }
    });

</script>
